﻿using log4net;
using log4net.Config;
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace Spiders
{
    class Program
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Program));

        static void Main(string[] args)
        {
            Console.Title = "网络爬虫程序";
            //ConsoleWin32Helper.ShowNotifyIcon();

            BaiduRobot robot = new BaiduRobot();
            robot.HttpGetZhidaoMainPage();
            robot.HttpGetNewBaiduIDCookie();
            string islogin = robot.HttpGetLoginInfo();
            if (islogin.Contains("1"))
            {
                log.Error("返回的检查是否登陆JSON字符串有错，应该为0，目前为1");
                return;
            }
            string token = robot.HttpGetApiInfo();
            robot.HttpLoginCheck(token, "30398931@qq.com");
            robot.HttpLogin(token, "30398931@qq.com", "xqlun1984927");
            robot.HttpRefresh();
            // 读取用户信息
            robot.HttpGetUserInfo();
            // 获取全部关键字对应的问题
            robot.HttpGetAllKeywordQuestion();
            // 随机选取问题并回答
            robot.HttpPostSubmit();

            Console.ReadKey();
        }
    }

    class ConsoleWin32Helper
    {
        static NotifyIcon _NotifyIcon = new NotifyIcon();

        static ConsoleWin32Helper()
        {
            _NotifyIcon.Icon = new Icon(@"F:\\project\\web-spiders\\Spiders\\Spiders\\agt_web.ico");
            _NotifyIcon.Visible = false;
            _NotifyIcon.Text = "Spider";

            ContextMenu menu = new ContextMenu();
            MenuItem item = new MenuItem();
            item.Text = "右键菜单";
            item.Index = 0;

            menu.MenuItems.Add(item);
            _NotifyIcon.ContextMenu = menu;

            _NotifyIcon.MouseDoubleClick += new MouseEventHandler(_NotifyIcon_MouseDoubleClick);
        }

        static void _NotifyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
        {

        }

        public static void ShowNotifyIcon()
        {
            _NotifyIcon.Visible = true;
            _NotifyIcon.ShowBalloonTip(3000, "", "123", ToolTipIcon.None);
        }

        public static void HideNotifyIcon()
        {
            _NotifyIcon.Visible = false;
        }
    }
}
